package com.bosssoft.hr.javase;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapExample {
    public Map<Integer, Student> map = new HashMap();

  public   Student put(int key, Student value) {
      map.put(key, value);
        return map.get(key);
    }

  public   Student remove(int key) {
      Student student=new Student(1,"张三");
      map.put(1,student);
      map.put(key,student);
      return map.remove(key);
    }

   public boolean containsKey(int key) {
      Student student=new Student();
      student.setId(1);
      student.setName("张三");
      map.put(key,student);
        return map.containsKey(key);
    }

  public   void visitByEntrySet() {
        System.out.println("visitByEntrySet");
      Student student=new Student();
      student.setId(1);
      student.setName("张三");
      map.put(1,student);
        for (Map.Entry<Integer, Student> entry : this.map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue().toString());
        }
    }

  public   void visitByKeySet() {
        System.out.println("visitByKeySet");
      Student student=new Student();
      student.setId(1);
      student.setName("san");
      map.put(1,student);
        Set<Integer> integers = map.keySet();
        for (Integer key : integers) {
            System.out.println(map.get(key));
        }
    }

  public   void visitByValues() {
        System.out.println("visitByValues");
      Student student=new Student();
      student.setId(1);
      student.setName("san");
      map.put(1,student);
        Collection<Student> values = map.values();
        for (Student u : values) {
            System.out.println(u.toString());
        }
    }

}
